package com.dao.impl;

import com.dao.BaseDeo;
import com.dao.FeatureDao;
import com.entity.feature.Feature;
import com.entity.feature.FeatureLevel;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class FeatureDaoImpl extends BaseDeo implements FeatureDao {
	@Override
	public List<Feature> getFeatureList() {
		//连接数据库
		oldLinkConn();
		//查询数据
		//language=MySQL
		String sql = "SELECT fe.id as id,fe.level_id as levelId, fe.affected_versions as affectedVersions, fe.`name` as name, fe.description AS description, fe.date as date,fe.cover as cover,le.`name` as uname  from feature fe,feature_level le WHERE le.id=fe.level_id";
		ResultSet rs = exeQuery(sql);
		List<Feature> featureList = new ArrayList<>();
		List<FeatureLevel> featureLevelList = new ArrayList<>();
		Feature feature = null;
		try {
			while (rs.next()) {
				feature = new Feature();
				feature.setId(rs.getInt("id"));
				feature.setLevelId(rs.getInt("levelId"));
				feature.setAffectedVersions(rs.getString("affectedVersions"));
				feature.setName(rs.getString("name"));
				feature.setDescription(rs.getString("description"));
				feature.setDate(rs.getString("date"));
				
				feature.setCover(rs.getString("cover"));
				featureList.add(feature);
			}
		} catch (Exception e) {
			System.out.println("Feature表查询失败！");
		} finally {
			closeAll(rs);
		}
		return featureList;
	}
	
	@Override
	public Feature getFeature(int featureId) {
		return null;
	}
	
	@Override
	public int addFeature(Feature feature) {
		return 0;
	}
	
	@Override
	public void updateFeature(Feature feature) {
	
	}
	
	@Override
	public void deleteFeature(int featureId) {
	
	}
	
	@Override
	public List<String> getLevelList() {
		//连接数据库
		oldLinkConn();
		//查询数据
		//language=MySQL
		String sql = "SELECT * FROM feature_level";
		ResultSet rs = exeQuery(sql);
		List<String> levelList = new ArrayList<>();
		try {
			while (rs.next()) {
				FeatureLevel featureLevel = new FeatureLevel();
				levelList.add(rs.getString("name"));
			}
		}catch (Exception e){
			System.out.println("FeatureLevel表查询失败！");
		}finally {
			closeAll(rs);
		}
		return levelList;
	}
	
	@Override
	public String getLevel(int levelId) {
		return "";
	}
	
	@Override
	public void deleteLevel(int levelId) {
	
	}
	
	@Override
	public String getFeatureName(int featureId) {
		return "";
	}
	
	@Override
	public String getFeatureDescription(int featureId) {
		return "";
	}
	
	@Override
	public String getFeatureLevel(int featureId) {
		return "";
	}
	
	@Override
	public String getFeatureAffectedVersions(int featureId) {
		return "";
	}
	
	@Override
	public String getFeatureCover(int featureId) {
		return "";
	}
	
	@Override
	public String getFeatureDate(int featureId) {
		return "";
	}
	
	@Override
	public String getFeatureStatus(int featureId) {
		return "";
	}
	
	@Override
	public int getFeatureId(String name) {
		return 0;
	}
	
	@Override
	public int getLevelId(String level) {
		return 0;
	}
	
	@Override
	public void updateLevel(String level) {
	
	}
	
	@Override
	public int addLevel(String level) {
		return 0;
	}

}
